package adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.customview.R;

import java.io.File;
import java.util.List;

/**
 * Created by eyesee on 2017/4/20.
 */

public class FileManagerVideoListAdapter extends BaseAdapter {

//    private List<String> list;
    private List<File> list;
    private Context mContext;
    private int mItemHeight;

    /*public FileManagerVideoListAdapter(Context context, List<String> list) {
        this.list = list;
        this.mContext = context;
    }*/
    public FileManagerVideoListAdapter(Context context, List<File> list) {
        this.list = list;
        this.mContext = context;
    }

    public int getItemHeight(){
        return mItemHeight;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView==null){
            holder = new ViewHolder();
            convertView=View.inflate(mContext, R.layout.videolist_item_two,null);
            mItemHeight = convertView.getMeasuredHeight();
            holder.mTextView= (TextView) convertView.findViewById(R.id.videolist_textview);
            holder.mImageView = (ImageView) convertView.findViewById(R.id.videolist_img);
            holder.mVideoUp = ((ImageView) convertView.findViewById(R.id.videolist_videoup));
            holder.mVideoPlay = ((ImageView) convertView.findViewById(R.id.videolist_play));

            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        //通过position拿到item对应的File,判断File为directory则设置文件夹背景,隐藏部分图片,
        // 否则设置获取视频缩略图设置为背景
        if (list.get(position).isDirectory()){
            holder.mVideoUp.setVisibility(View.INVISIBLE);
            holder.mVideoPlay.setVisibility(View.INVISIBLE);
            holder.mTextView.setText(list.get(position).getName());
            holder.mImageView.setImageResource(R.drawable.file_folder);
        }else {
            holder.mVideoUp.setVisibility(View.VISIBLE);
            holder.mVideoPlay.setVisibility(View.VISIBLE);
            holder.mTextView.setText(list.get(position).getName());
            holder.mImageView.setBackgroundResource(R.drawable.pic);
        }

            /*if (position%2==0){
                holder.mVideoUp.setVisibility(View.INVISIBLE);
                holder.mVideoPlay.setVisibility(View.INVISIBLE);
                holder.mTextView.setText(list.get(position).getName());
                holder.mImageView.setImageResource(R.drawable.file_folder);
            }else {
                holder.mVideoUp.setVisibility(View.VISIBLE);
                holder.mVideoPlay.setVisibility(View.VISIBLE);
                holder.mTextView.setText(list.get(position).getName());
                holder.mImageView.setBackgroundResource(R.drawable.pic);
            }*/
        return convertView;
    }


    class ViewHolder{
        TextView mTextView;
        ImageView mImageView;
        ImageView mVideoUp;
        ImageView mVideoPlay;
    }
}
